#coding:utf-8
# Django settings for lovewith project.
import os.path

ROOT = os.path.dirname(os.path.abspath(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

SITE_URL = 'http://www.lovewith.me:8000/'

ADMINS = (
    ('cosa', 'etosun@qq.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'lovewith',  # Or path to database file if using sqlite3.
        'USER': 'root',  # Not used with sqlite3.
        'PASSWORD': 'root',  # Not used with sqlite3.
        'HOST': '127.0.0.1',  # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',  # Set to empty string for default. Not used with sqlite3.
    }
}


#用于生产环境的配置
try:
    from settings_deploy import *

    pass
except ImportError:
    pass


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Asia/Shanghai'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'zh-cn'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = False

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(ROOT, "static/upload").replace("\\", "/")

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(ROOT, "static").replace("\\", "/")

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = SITE_URL + "static/"

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
    #'compressor.finders.CompressorFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'fyhq!7nt(-^jh*kj%+48g!jq$23lt@$k8hne8#b)v==kelxa0#'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    #'django.template.loaders.filesystem.Loader',
    #'django.template.loaders.app_directories.Loader',
    #'django.template.loaders.eggs.Loader',
    'django_jinja.loaders.AppLoader',
    'django_jinja.loaders.FileSystemLoader'

)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    #显示中文
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    #压缩html
    'pipeline.middleware.MinifyHTMLMiddleware',
    #Uncomment the next line for simple clickjacking protection:
    #'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #自定义中间件，用于实现二级域名访问
    'lovewith.customMiddleware.SubdomainMiddleware',
    #判断是否登录并写登录cookie
    #'lovewith.customMiddleware.SignMiddleware',
    'django_user_agents.middleware.UserAgentMiddleware',
    #显示IP
    'lovewith.customMiddleware.SetRemoteAddrFromForwardedFor',
)

ROOT_URLCONF = 'lovewith.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'lovewith.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(ROOT, 'templates/'),
)

INSTALLED_APPS = (
    'django_jinja',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'grappelli',
    'django.contrib.admin',
    'django.contrib.admindocs',
    #搜索
    'haystack',
    'lovewith.website',
    'lovewith.promote',
    'lovewith.account',
    'lovewith.share',
    'lovewith.magazine',
    'lovewith.subscribe',
    'lovewith.album',
    'lovewith.card',
    'lovewith.supplier',
    'lovewith.analytics',
    #'django_jinja.contrib.pipeline',
    #'compressor'
    'django_user_agents',
)

#域名
SESSION_COOKIE_DOMAIN = ".lovewith.me"

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.

#session过期时间(秒)
#SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 86400 * 4  # 4天

AUTH_USER_MODEL = 'account.MtUser'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'

#@login_required跳转地址
LOGIN_URL = SITE_URL + 'u/sign/'

#临时文件保存路径
FILE_UPLOAD_TEMP_DIR = os.path.join(ROOT, 'static/upload/upload.tmp/').replace("\\", "/")
FILE_UPLOAD_HANDLERS = ('django.core.files.uploadhandler.TemporaryFileUploadHandler',)

#文件上传路径
FILE_UPLOAD_PATH = os.path.join(ROOT, "static/upload/").replace("\\", "/")

#分页大小(8n)
PAGE_SIZE = 80

#默认模板文件扩展名
DEFAULT_JINJA2_TEMPLATE_EXTENSION = '.jinja'


#邮件设置
EMAIL_HOST = 'smtp.exmail.qq.com'  # 设置邮箱的SMTP的服务器
EMAIL_HOST_USER = 'guanliyuan@lovewith.me'  # 邮箱账号
EMAIL_HOST_PASSWORD = 'love99'  # 邮箱密码
EMAIL_PORT = 25  # 配置邮箱的端口号


HAYSTACK_SOLR_URL = 'http://127.0.0.1:8983/solr/'
HAYSTACK_DEFAULT_OPERATOR = 'AND'

HAYSTACK_CONNECTIONS = {
    #'default': {
    #    'ENGINE': 'haystack.backends.whoosh_cn_backend.WhooshEngine',
    #    'PATH': os.path.join(ROOT, 'whoosh_index'),
    #},
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr'
        # ...or for multicore...
        # 'URL': 'http://127.0.0.1:8983/solr/mysite',
    },
}



#CACHES = {
#    'default': {
#        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
#        'LOCATION': '127.0.0.1:11211',
#    }
#}


#STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
#PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.slimit.SlimItCompressor'
#PIPELINE_CSS = {
#    'main': {
#        'source_filenames': (
#            'css/reset.css',
#            'css/common.css',
#            'css/main.css'
#        ),
#        'output_filename': 'css/style.css'
#    },
#}
#



#LOGGING = {
#    'version': 1,
#    'disable_existing_loggers': False,
#    'handlers': {
#        'console':{
#            'level':'DEBUG',
#            'class':'logging.StreamHandler',
#        },
#    },
#    'loggers': {
#        'django.db.backends': {
#            'handlers': ['console'],
#            'propagate': True,
#            'level':'DEBUG',
#        },
#    }
#}